package com.lotter.api.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lotter.api.service.MobileCodeService;
import com.lotter.api.service.SmsService;
import com.lotter.common.enumobject.SiteMessageFormat;
import com.lotter.invocation.StaticDataContext;

@Controller
@RequestMapping(value="/website/sms")
public class SmsWebSiteController extends BaseController{
	
	
	@Autowired
	private SmsService smsservice;
	
	@Autowired
	private MobileCodeService mobileCodeService ;
	/**
	 * 绑卡发送验证码
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/insertBank",method=RequestMethod.GET)
	public Map<String,Object> insertBankSms(@RequestParam(value ="token",required = true) String token){
		String mobile = StaticDataContext.onLineMobile(token);
		boolean bool = mobileCodeService.whether(mobile);
		if(bool){
			return ajaxLotterStage("手机验证码已经发送过不要重复发送");
		}
		SiteMessageFormat siteMessageFormat = SiteMessageFormat.BIND_BIND_NOTICE;
		smsservice.sendSms(mobile, siteMessageFormat);
		return ajaxLotterSuccess();
	}
	
	
	/**
	 * 绑卡发送验证码
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/updateBank",method=RequestMethod.GET)
	public Map<String,Object> updateBank(@RequestParam(value ="token",required = true) String token){
		String mobile = StaticDataContext.onLineMobile(token);
		boolean bool = mobileCodeService.whether(mobile);
		if(bool){
			return ajaxLotterStage("手机验证码已经发送过不要重复发送");
		}
		SiteMessageFormat siteMessageFormat = SiteMessageFormat.UPDATE_NEWBIND_NOTICE;
		smsservice.sendSms(mobile, siteMessageFormat);
		return ajaxLotterSuccess();
	}
	
	/**
	 * 更新支付密码
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/payPassWord",method=RequestMethod.GET)
	public Map<String,Object> payPassWord(@RequestParam(value ="token",required = true) String token){
		String mobile = StaticDataContext.onLineMobile(token);
		boolean bool = mobileCodeService.whether(mobile);
		if(bool){
			return ajaxLotterStage("手机验证码已经发送过不要重复发送");
		}
		SiteMessageFormat siteMessageFormat = SiteMessageFormat.PAY_PWD_NOTICE;
		smsservice.sendSms(mobile, siteMessageFormat);
		return ajaxLotterSuccess();
	}


}
